﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinformScanner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }             
        private void button1_Click(object sender, EventArgs e)
        {       
                string url = textBox1.Text;
                try
                {                   
                    WebClient client = new WebClient();// 使用 WebClient 获取页面内容
                    string pageContent = client.DownloadString(url);
                    string phoneNumberPattern = @"\b\s*0\d{2,3}\s*-\s*\d{7,8}\s*\b";; //正则表达式查找电话号码
                    MatchCollection phoneNumberMatches = Regex.Matches(pageContent, phoneNumberPattern);
                    foreach (Match match in phoneNumberMatches)
                    {
                        string phoneNumber = match.Value;
                        TelBox.Items.Add(phoneNumber);
                       
                    }
                    
                string emailPattern = @"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";// 正则表达式查找邮箱
                    MatchCollection emailMatches = Regex.Matches(pageContent, emailPattern);
                    foreach (Match match in emailMatches)
                    {
                        string email = match.Value;
                        MailBox.Items.Add(email);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误: " + ex.Message);//抛出非法输入警告
                }

        }

        
    }
}
